package com.starblink.android.basic.util;

import static com.starblink.android.basic.ext.ViewExtKt.toast;

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;

import com.starblink.basic.util.CommUtils;

import java.util.ArrayList;

/**
 * 意图相关实用方法
 * 1.发送邮件
 */
public class IntentUtils {
    /**
     * 发送纯文本
     *
     * @param content 内容
     * @param subject 主题
     */
    public static void sendMailOnlyText(String content, String subject) {
        Intent intent = new Intent(Intent.ACTION_SENDTO);
        intent.setData(Uri.parse("mailto:support@getguang.com"));
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
        intent.putExtra(Intent.EXTRA_TEXT, content);
        Intent createChooser = Intent.createChooser(intent, "Choose Email Client");
        createChooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        try{
            CommUtils.getContext().startActivity(createChooser);
        } catch (ActivityNotFoundException e){
            toast("Email client not installed");
        }
    }

    /**
     * 发送一个附件 TODO
     */
    public static void sendMailOneAttachment() {
        Intent intent = new Intent(Intent.ACTION_SEND);
        String[] tos = {""};//收件人
        String[] ccs = {""};//抄送人
        String[] bccs = {""};//密送人
        intent.putExtra(Intent.EXTRA_EMAIL, tos);
        intent.putExtra(Intent.EXTRA_CC, ccs);
        intent.putExtra(Intent.EXTRA_BCC, bccs);
        intent.putExtra(Intent.EXTRA_TEXT, "内容");
        intent.putExtra(Intent.EXTRA_SUBJECT, "主题");

        intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/测试结果.html"));
        intent.setType("text/html");
        intent.setType("message/rfc882");
        Intent.createChooser(intent, "Choose Email Client");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        CommUtils.getContext().startActivity(intent);
    }


    /**
     * 发送多个附件 TODO
     */
    public static void sendMailMoreAttachments() {
        Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
        String[] tos = {""};//收件人
        String[] ccs = {""};//抄送人
        String[] bccs = {""};//密送人
        intent.putExtra(Intent.EXTRA_EMAIL, tos);
        intent.putExtra(Intent.EXTRA_CC, ccs);
        intent.putExtra(Intent.EXTRA_BCC, bccs);
        intent.putExtra(Intent.EXTRA_TEXT, "内容");
        intent.putExtra(Intent.EXTRA_SUBJECT, "主题");

        ArrayList<Uri> imageUris = new ArrayList<Uri>();
        imageUris.add(Uri.parse("file:///sdcard/测试结果.html"));
        imageUris.add(Uri.parse("file:///sdcard/测试结果.html"));
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
        intent.setType("text/html");
        intent.setType("message/rfc882");
        Intent.createChooser(intent, "Choose Email Client");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        CommUtils.getContext().startActivity(intent);
    }

}
